// ClientDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Client.h"
#include "ClientDlg.h"
#include "Defines.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

/*
struct PackageDefine
{
	char SIGN_IN = '1';
	char SIGN_OUT = '2';
	char SEND = '3';
};
*/

// CClientDlg dialog

CString filename;
long lSize;
int _block_size;

static int GetInteger(char* buff, int index)
{
	char s[4];
	strncpy(s, buff + index, 4);
	return atoi(s);
}

CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CClientDlg::IDD, pParent)
	, m_port(0)
	, m_ipAddress(_T(""))
	, isDownloading(false)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CClientDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST_ONLINE, m_clientList);
}

BEGIN_MESSAGE_MAP(CClientDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_EXIT, &CClientDlg::OnBnClickedExit)
	ON_BN_CLICKED(IDC_BTN_CONECT, &CClientDlg::OnBnClickedBtnConect)
	ON_BN_CLICKED(IDC_BTN_STOP, &CClientDlg::OnBnClickedBtnStop)
	ON_BN_CLICKED(IDC_BTN_SEND, &CClientDlg::OnBnClickedBtnSend)
	ON_BN_CLICKED(IDC_BTN_SEND_FILE, &CClientDlg::OnBnClickedBtnSendFile)
END_MESSAGE_MAP()


// CClientDlg message handlers

BOOL CClientDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	m_socket.pDlg = this;
	m_port = 2000;
	m_ipAddress = _T("127.0.0.1");
	//m_ipAddress = _T("153.254.134.208");
/*
	LVITEM lvItem;

	lvItem.mask = LVIF_TEXT;
	lvItem.iItem = 0;
	lvItem.iSubItem = 0;
	char* text = "Item 1";
	wchar_t wtext[50];
	mbstowcs(wtext, text, strlen(text)+1);
	LPWSTR ptr = wtext;
	lvItem.pszText = ptr;
	m_clientList.InsertItem(&lvItem);
*/
	//AddClientListItem(2000);

	m_clientList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES);

	for(int i=0; i<MAX_CLIENT; i++)
	{
		m_clientOnlineArr[i] = -1;
	}

	GetDlgItem(IDC_BTN_CONECT)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_STOP)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SEND)->EnableWindow(FALSE);

	SetDlgItemText(IDC_EDIT_IPADDRESS, m_ipAddress);

	m_file = NULL;
/*
	_block_size = 0;
	fBuff = NULL;
	fSize = 0;

	char buff[1000];
	int block_size = 256;
	int count = 0;
	int seek = 0;
	FILE* fr = fopen("C:\\test.jpg", "rb");
	FILE* fw = fopen("C:\\test_write.jpg", "wb");
	int block_read = 0;
	int block_write = 0;
	int FSize = 18709;
	if(fr != NULL)
	{
		while(seek < FSize)
		{
			count = FSize - seek;
			if(count > block_size)
				count = block_size;
			block_read = fread(buff, 1, count, fr);
			block_write = fwrite(buff, 1, count, fw);
			seek += count;
		}
	}
	fclose(fr);
	fclose(fw);
*/
/*
	unsigned int k = 1720613;
	unsigned int kk = htonl(k);
*/
// 	int k = 1720613;
// 	int kk = htonl(k);

	SetWindowLong(this->m_hWnd, GWL_STYLE, GetWindowLong(this->m_hWnd, GWL_STYLE) | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CClientDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CClientDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CClientDlg::OnBnClickedExit()
{
	AfxGetMainWnd()->PostMessage(WM_CLOSE);
}

bool CClientDlg::OnSend(void)
{
	char buff[BUFF_SIZE];
	char str[BUFF_SIZE];
	GetDlgItemTextA(this->GetSafeHwnd(), IDC_EDIT_SEND_MSG, str, BUFF_SIZE);
	sprintf(buff, "%d%s", m_socket.m_clientID, str);
	//m_socket.Send(buff, BUFF_SIZE);
	OutputDebugString(_T("[Client Dlg] Send msg"));
	OutputDebugStringA(buff);
	return false;
}

int CClientDlg::OnReceive(char* buff, int size)
{
	OutputDebugString(_T("[Client Dlg] OnReceive"));
	int clientID = -1;
	CString str;
	int clientOnlineNum = 0;
#ifdef USE_PACKAGE
	m_package.LoadData((byte*)m_szBuff);
	switch(m_package.type)
	{
		case TYPE::CHATTING:
			{
				switch(m_package.action)
				{
					case ACTION::CHAT_SIGNIN:
						{
							m_clientList.DeleteAllItems();
							OutputDebugString(_T("--- Sign in"));
							//clientOnlineNum = m_szBuff[1] - '0';
							clientID = ReadINT32((byte*)m_szBuff, m_package.dataOffset);
							if(m_socket.m_clientID < 0)
							{
								m_socket.m_clientID = clientID;
								str.Format(_T("Client %d"), clientID);
								SetWindowText(str);
							}
							else
							{
								OutputDebugString(_T("Other client sign in"));
							}
						}
						break;
					case ACTION::CHAT_SEND_MESSAGE:
						{
							OutputDebugString(_T("--- Get message"));
							int srcClientID = ReadINT32((byte*)m_szBuff, m_package.dataOffset);
							char* msg = (m_szBuff + m_package.dataOffset + 8);
							CString str;
							GetDlgItemText(IDC_EDIT_RECEIVE_MSG, str);
							CString s(msg);
							str.Append(s);
							str.Append(_T("\r\n"));
							GetDlgItem(IDC_EDIT_RECEIVE_MSG)->SetWindowText(str);
						}
						break;
					case ACTION::CHAT_SIGNOUT:
						{

						}
						break;
					default:
						break;
				}
			}
			break;
		case TYPE::FILE_TRANSFER:
			{
				OutputDebugString(_T("*** FILE_TRANSFER ***"));
				switch(m_package.action)
				{
					case ACTION::FILE_HEADER:
						break;
					case ACTION::FILE_START:
						OutputDebugString(_T("[Client Dlg]: FILE_START"));
						//fBuff = new byte[fSize];
						m_file = fopen(fName, "rb");
						m_package.type = TYPE::FILE_TRANSFER;
						//m_package.action = ACTION::FILE_SEND;
						m_package.action = ACTION::FILE_START;
						m_package.dataOffset = 6;
						m_fSeek = 0;
						//m_fSeek = fread(m_package.data, 1, sizeof(m_package.data), m_file);
						m_package.WriteToBuffer((byte*)m_szBuff);
						m_socket.Send(m_szBuff, sizeof(m_szBuff));
						OutputDebugString(_T("[Client Dlg]: FILE_START - end"));
						break;
					case ACTION::FILE_SEND:
						OutputDebugString(_T("[Client Dlg]: FILE_SEND"));
						if(m_file != NULL)
						{
							m_package.type = TYPE::FILE_TRANSFER;
							m_package.action = ACTION::FILE_SEND;
							m_package.dataOffset = 6;
							m_package.dataSize = fSize - m_fSeek;
							char str[10];
							itoa(m_fSeek, str, 10);
							OutputDebugString(_T("Seek:"));
							OutputDebugStringA(str);
// 							while(seek < FSize)
// 							{
// 								count = FSize - seek;
// 								if(count > block_size)
// 									count = block_size;
// 								block_read = fread(buff, 1, count, fr);
// 								block_write = fwrite(buff, 1, count, fw);
// 								seek += count;
// 							}
							if(m_fSeek < fSize)
							{
								m_package.dataSize = fSize - m_fSeek;
								if(m_package.dataSize > BLOCK_SIZE)
								{
									m_package.dataSize = BLOCK_SIZE;
								}
								OutputDebugString(_T("[Client Dlg]: Send Data"));
								memset(m_package.data, 0, sizeof(m_package.data));
								_block_size = fread(m_package.data, 1, BLOCK_SIZE, m_file);
								m_fSeek += BLOCK_SIZE;
								m_package.WriteToBuffer((byte*)m_szBuff);
								int sendSize = m_socket.Send(m_szBuff, BUFF_SIZE);
								char str[256];
								sprintf(str, "[Client Dlg]: Send buff size: %d", sendSize);
								printf("GGGGGGGGGGGGGGGGGGGG");
								OutputDebugStringA(str);
								//m_socket.Send(m_szBuff, _block_size);
							}
							else
							{
								OutputDebugString(_T("[Client Dlg]: Send STOP"));
								m_package.type = TYPE::FILE_TRANSFER;
								m_package.action = ACTION::FILE_STOP;								
								m_package.WriteToBuffer((byte*)m_szBuff);
								m_socket.Send(m_szBuff, BUFF_SIZE);
							}
/*
							if(m_package.dataSize > sizeof(m_package.data))
							{
								m_package.dataSize = sizeof(m_package.data);
							}
							if(m_package.dataSize > 0)
							{
								OutputDebugString(_T("[Client Dlg]: Send Data"));
								memset(m_package.data, 0, m_package.dataSize);
								//byte tmp[1000];
								//fread(tmp, 1, 1000, m_file);
								_block_size = fread(m_package.data, 1, m_package.dataSize, m_file);
								m_fSeek += m_package.dataSize;
								m_package.WriteToBuffer((byte*)m_szBuff);
								//m_socket.Send(m_szBuff, sizeof(m_szBuff));
								m_socket.Send(m_szBuff, _block_size);
							}
							else
							{
								OutputDebugString(_T("[Client Dlg]: Send STOP"));
								m_package.type = TYPE::FILE_TRANSFER;
								m_package.action = ACTION::FILE_STOP;
								m_package.WriteToBuffer((byte*)m_szBuff);
								m_socket.Send(m_szBuff, sizeof(m_szBuff));
							}
*/
						}
						OutputDebugString(_T("[Client Dlg]: FILE_SEND - end"));
						break;
					case ACTION::FILE_STOP:
						OutputDebugString(_T("[Client Dlg]: FILE_STOP"));
						if(m_file != NULL)
						{
							fclose(m_file);
							m_file = NULL;
						}
						OutputDebugString(_T("[Client Dlg]: FILE_STOP - end"));
						break;
				}
			}
			break;
		default:
			OutputDebugString(_T("---- Receive ERROR ----"));
			break;
	}
#else	//USE_PACKAGE
	switch(m_szBuff[0])
	{
		case Defines::SIGN_IN:
			m_clientList.DeleteAllItems();
			OutputDebugString(_T("--- Sign in"));
			clientOnlineNum = m_szBuff[1] - '0';
			clientID = GetInteger(m_szBuff, 2);
			if(m_socket.m_clientID < 0)
			{
				m_socket.m_clientID = clientID;
				str.Format(_T("Client %d"), clientID);
				SetWindowText(str);
			}
			/*
			if(clientID != m_socket.m_clientID)
			{
				str.Format(_T("Client %d"), clientID);
				SetWindowText(str);
			}
			*/
			if(true)
			{
				int index = 6;
				for(int i=0; i<clientOnlineNum; i++)
				{
					m_clientOnlineArr[i] = GetInteger(m_szBuff, index);
					index += 4;
					/*
					if(m_clientOnlineArr[i] < 0)
					{
						m_clientOnlineArr[i] = clientID;
						break;
					}
					*/
				}
			}
			for(int i=0; i<MAX_CLIENT; i++)
			{
				if(m_clientOnlineArr[i] >= 0)
				{
					AddClientListItem(m_clientOnlineArr[i]);
				}
			}
			
			break;
		case Defines::SIGN_OUT:
			{
				int clientOutID = GetInteger(m_szBuff, 1);
				int k = -1;
				int n = m_clientList.GetItemCount();
				for(int i=0; i<n; i++)
				{
					CString s = m_clientList.GetItemText(i, 0);
					if(_tstoi(s.Mid(7)) == clientOutID)
					{
						k = i;
					}
				}
				if(k >= 0)
				{
					m_clientList.DeleteItem(k);
				}
				clientOnlineNum--;
				OutputDebugString(_T("--- Sign out"));
			}
			break;
		case Defines::SEND:
			{
				OutputDebugString(_T("--- Send"));
				int srcClientID = GetInteger(m_szBuff, 5);
				char* msg = (m_szBuff + 9);
				CString str;
				GetDlgItemText(IDC_EDIT_RECEIVE_MSG, str);
				CString s(msg);
				str.Append(s);
				str.Append(_T("\r\n"));
				GetDlgItem(IDC_EDIT_RECEIVE_MSG)->SetWindowText(str);
			}
			break;
		case Defines::SENDING_FILE:
			{
				if(strncmp(m_szBuff+1, "-OK-", 4) == 0)
				{
					//MessageBox(_T("Chap nhan file"));
					OutputDebugString(_T("[Client Dlg] Chap nhan file"));
					char fName[256];
					sprintf(fName, "%S", (char*)filename.GetBuffer());
					FILE *f = fopen(fName, "r");
					if(f != NULL)
					{
						memset(m_szBuff, 0, BUFF_SIZE);
						OutputDebugString(_T("Reading file..."));
						fseek (f , 0 , SEEK_END);
						lSize = ftell (f);
						rewind (f);

						char* fBuff = new char[lSize];
						fread(fBuff, sizeof(char), lSize, f);
						//m_socket.m_clientID = 1000;
						sprintf(m_szBuff, "5START%d%ld", m_socket.m_clientID, lSize);
						
						memcpy(m_szBuff + 16, fBuff, 1000);
						m_socket.Send(m_szBuff, BUFF_SIZE);
						fclose(f);
						delete fBuff;
					}
					else
					{
						OutputDebugString(_T("Can't read file"));
					}

				}
				else if(strncmp(m_szBuff+1, "-NO-", 4) == 0)
				{
					MessageBox(_T("Khong nhan file"));
				}
				else if(strncmp(m_szBuff+1, "-SENDING-", 9) == 0)
				{

				}
			}
			break;
		default:
			OutputDebugString(_T("--- Error"));
			break;
	}
	/*
	CString str;
	GetDlgItemText(IDC_EDIT_RECEIVE_MSG, str);
	CString s(buff);
	str.Append(s);
	GetDlgItem(IDC_EDIT_RECEIVE_MSG)->SetWindowText(str);
	*/
#endif	//USE_PACKAGE
	return 0;
}

void CClientDlg::OnBnClickedBtnConect()
{
	UpdateData();
	if(AfxSocketInit() == FALSE)
	{
		AfxMessageBox(_T("Failed to Initialize Sockets")); 
		return; 
	}

	if(m_socket.Create() == FALSE)
	{
		MessageBox(_T("Failed to Create Socket"));
		return;
	}
	CString s;
	//GetDlgItemText(IDC_EDIT_IPADDRESS, s);
	//m_ipAddress = s;
	GetDlgItemText(IDC_EDIT_IPADDRESS, m_ipAddress);
	if(m_socket.Connect(m_ipAddress, m_port) == FALSE)
	{
		MessageBox(_T("Failed to Connect"));
		m_socket.Close();
		return;
	}

	GetDlgItem(IDC_BTN_CONECT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_STOP)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_SEND)->EnableWindow(TRUE);
}

void CClientDlg::OnBnClickedBtnStop()
{
	int k = -1;
	int n = m_clientList.GetItemCount();
	for(int i=0; i<n; i++)
	{
		CString s = m_clientList.GetItemText(i, 0);
		if(_tstoi(s.Mid(7)) == m_socket.m_clientID)
		{
			k = i;
		}
	}
	if(k >= 0)
	{
		m_clientList.DeleteItem(k);
	}


	m_clientOnlineArr[k] = -1;


	char buff[1000];
	//sprintf(buff, "2%d%s", m_socket.m_clientID, "exit");
	sprintf(buff, "2%d", m_socket.m_clientID);
	m_socket.Send(buff, BUFF_SIZE);
	m_socket.m_clientID = -1;
	GetDlgItem(IDC_BTN_CONECT)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_STOP)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SEND)->EnableWindow(FALSE);
	m_socket.Close();

	
}

void CClientDlg::OnBnClickedBtnSend()
{
#ifdef USE_PACKAGE
	SendToClient(1000);
#else	//USE_PACKAGE
	//OnSend();
	int n = m_clientList.GetItemCount();
	
	//UINT u = m_clientList.GetItemState(0, LVIF_TEXT);

	for(int i=0; i<n; i++)
	{
		if(m_clientList.GetCheck(i))
		{
			CString s = m_clientList.GetItemText(i, 0);
			int k = _tstoi(s.Mid(7));
			//SendToClient(1001);
			SendToClient(k);
		}
	}
#endif	//USE_PACKAGE
	SetDlgItemText(IDC_EDIT_SEND_MSG, _T(""));
}

int CClientDlg::AddClientListItem(int clientID)
{
	LVITEM lvItem;

	lvItem.mask = LVIF_TEXT;
	lvItem.iItem = 0;
	lvItem.iSubItem = 0;
	//char* text = "Item 1";
	wchar_t wtext[50];
	char text[20];

	sprintf(text, "Client %d", clientID);
	
	mbstowcs(wtext, text, strlen(text)+1);
	LPWSTR ptr = wtext;
	lvItem.pszText = ptr;
	m_clientList.InsertItem(&lvItem);
	return 0;
}

int CClientDlg::SendToClient(int clientID)
{
#ifdef USE_PACKAGE
	m_package.type = TYPE::CHATTING;
	m_package.action = ACTION::CHAT_SEND_MESSAGE;
	char str[BUFF_SIZE];
	GetDlgItemTextA(this->GetSafeHwnd(), IDC_EDIT_SEND_MSG, str, BUFF_SIZE);
	WriteINT32(m_socket.m_clientID, m_package.data, 0);
	WriteINT32(clientID, m_package.data, 4);
	memcpy(m_package.data + 8, str, sizeof(m_package.data));
	m_package.WriteToBuffer((byte*)m_szBuff);
	m_socket.Send(m_szBuff, m_package.dataSize);
	//sprintf(m_szBuff, "%d%d%s", 3, m_socket.m_clientID, str);
#else	//USE_PACKAGE
	//m_szBuff
	//char buff[1000];
	char str[BUFF_SIZE];
	GetDlgItemTextA(this->GetSafeHwnd(), IDC_EDIT_SEND_MSG, str, BUFF_SIZE);
	sprintf(m_szBuff, "%d%d%d%s", 3, m_socket.m_clientID, clientID, str);
	//sprintf(m_szBuff, "%d%d%s", 3, m_socket.m_clientID, str);
	m_socket.Send(m_szBuff, BUFF_SIZE);
#endif	//USE_PACKAGE
	
	OutputDebugString(_T("[Client Dlg] Send msg"));
	OutputDebugStringA(m_szBuff);
	return 0;
}

void CClientDlg::OnBnClickedBtnSendFile()
{
	CFileDialog dlg(TRUE);
	
	//dlg.m_ofn.nMaxFile = 511;
	//dlg.m_ofn.lpstrFilter=_T("XML Files (*.xml)\0*.xml\0Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0");
	//dlg.m_ofn.lpstrTitle=_T("Save XML File As");

	dlg.m_ofn.lpstrFilter = _T("All Files (*.*)\0*.*\0\0");
	dlg.m_ofn.lpstrTitle=_T("Open file");
	/*
	dlg.m_ofn.nMaxFile = 1;
	dlg.m_ofn.lpstrFilter = _T("All Files (*.*)\0*.*\0\0");
	*/
	
	if(dlg.DoModal() == IDOK)
	{
		filename = dlg.GetPathName();
	}
	if(filename != "")
	{
#ifdef USE_PACKAGE
		SetDlgItemText(IDC_LAB_FILE_LOCATION, filename);

		//char fName[256];
		sprintf(fName, "%S", (char*)filename.GetBuffer());
		FILE *f = fopen(fName, "r");
		if(f != NULL)
		{
			OutputDebugString(_T("Reading file..."));
			fseek (f , 0 , SEEK_END);
			long lSize = ftell (f);
			rewind (f);

			m_package.type = TYPE::FILE_TRANSFER;
			m_package.action = ACTION::FILE_HEADER;

			WriteINT32((int)lSize, m_package.data, 0);
			strcpy((char*)(m_package.data + 4), fName);
			m_package.WriteToBuffer((byte*)m_szBuff);
			fclose(f);
			fSize = (int)lSize;
			//SendToClient(1000);
			//m_socket.Send(m_szBuff, m_package.dataSize);
			m_socket.Send(m_szBuff, BUFF_SIZE);
/*
			char* fBuff = new char[lSize];
			fread(fBuff, sizeof(char), lSize, f);
			m_socket.m_clientID = 1000;
			sprintf(m_szBuff, "%c%d", Defines.SENDING_FILE, m_socket.m_clientID);
			memcpy(m_szBuff + 5, fBuff, 1000);
			fclose(f);
			delete fBuff;
*/
		}
		else
		{
			OutputDebugString(_T("Can't read file"));
		}
		
#else	//USE_PACKAGE
		sprintf(m_szBuff, "4%d%S", m_socket.m_clientID, (char*)filename.GetBuffer());
		m_socket.Send(m_szBuff, BUFF_SIZE);
		/*
		if (MessageBox(_T("Are you sure?"), _T("Sure?"), MB_YESNO) == IDYES)
		{
			OutputDebugString(_T("1111111111111111111111"));
		}
		else
		{
			OutputDebugString(_T("22222222222222222222222222"));
		}
		*/
/*
		SetDlgItemText(IDC_LAB_FILE_LOCATION, filename);
		
		char fName[256];
		sprintf(fName, "%S", (char*)filename.GetBuffer());
		FILE *f = fopen(fName, "r");
		if(f != NULL)
		{
			OutputDebugString(_T("Reading file..."));
			fseek (f , 0 , SEEK_END);
			long lSize = ftell (f);
			rewind (f);

			char* fBuff = new char[lSize];
			fread(fBuff, sizeof(char), lSize, f);
			m_socket.m_clientID = 1000;
			sprintf(m_szBuff, "%c%d", Defines.SENDING_FILE, m_socket.m_clientID);
			memcpy(m_szBuff + 5, fBuff, 1000);
			fclose(f);
			delete fBuff;
		}
		else
		{
			OutputDebugString(_T("Can't read file"));
		}
*/
		
		/*
		CFile srcFile;
		CFileException fe;
		BOOL bFileIsOpen = FALSE;

		if( !( bFileIsOpen = srcFile.Open( filename, 
			CFile::modeRead | CFile::typeBinary, &fe ) ) )
		{
			MessageBox(_T("Can't open file"));
			return;
		}
		int fLen = srcFile.GetLength();
		fLen = htonl(fLen);
		//int _fLen = htonl(fLen);	//revert the bytes in int.
		int cbLeftToSend = sizeof( fLen );
		BOOL bRet = TRUE;
		*/
#endif	//USE_PACKAGE
	}
}
